package com.bibi.hanshunping.chapter06;

import java.util.Scanner;

public class ArrayAdd2 {
    public static void main(String[] args) {
        Scanner myScaner = new Scanner(System.in);
        int[] arr = {1, 2, 3};
        do{
            int[] arrNew = new int[arr.length + 1];
            for (int i = 0; i < arr.length; i++) {
                arrNew[i] = arr[i];
            }
            System.out.println("请输入你要添加的元素");
            int addNum = myScaner.nextInt();
            arrNew[arrNew.length - 1] = addNum;
            arr = arrNew;
            System.out.println("扩容后：");
            for (int i = 0; i < arr.length; i++) {
                System.out.print(arr[i] + "\t");
            }
            System.out.println("是否继续添加");
            char key = myScaner.next().charAt(0);
            if (key == 'n') {
                break;
            }
        } while (true);

        System.out.println("--end--");
    }
}
